import request from '@/utils/request'

// 获取商品列表
export function getGoodsList(params) {
  return request({
    url: '/api/product/list',
    method: 'get',
    params
  })
}

// 获取商品详情
export function getGoodsDetail(id) {
  return request({
    url: `/api/product/${id}`,
    method: 'get'
  })
}

// 创建商品
export function createGoods(data) {
  return request({
    url: '/goods',
    method: 'post',
    data
  })
}

// 创建或更新商品
export function saveGoods(data) {
  return request({
    url: '/api/product/save',
    method: 'post',
    data
  })
}

// 更新商品
export function updateGoods(id, data) {
  return request({
    url: `/goods/${id}`,
    method: 'put',
    data
  })
}

// 删除商品
export function deleteGoods(id) {
  return request({
    url: `/goods/${id}`,
    method: 'delete'
  })
}

// 批量删除商品
export function batchDeleteGoods(ids) {
  return request({
    url: '/goods/batch-delete',
    method: 'post',
    data: { ids }
  })
}

// 上架/下架商品
export function toggleGoodsStatus(id, status) {
  return request({
    url: `/goods/${id}/status`,
    method: 'patch',
    data: { status }
  })
}

// 获取商品分类
export function getGoodsCategories() {
  return request({
    url: '/goods/categories',
    method: 'get'
  })
}